/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cart;

import bean.ProductBean;
import ejb.OrderDetail;
import ejb.Product;
import java.math.BigDecimal;
import java.util.List;
import jsf.OrderController;

/**
 *
 * @author longdm
 */
public class CartItem {
    private Product product;
    private int quantity;

    public CartItem() {
    }


    public CartItem(Product product, int quantity) {
        this.product = product;
        this.quantity = quantity;
    }

    public int getTotal()
    {
        return product.getPrice()*quantity;
    }

    public int getTotalPrice()
    {
        int total = 0;
        ProductBean pb = new ProductBean();
        List<Product> list = pb.getAllProduct();
        for(Product p :list)
        {
            total = total + p.getPrice()*quantity;
        }
        return total;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
//---------------------------------------------------------------------------------------

    private OrderDetail currentOrderDetail;

    OrderController oc = new OrderController();
    public void toOrderDetail()
    {
        currentOrderDetail = new OrderDetail();
        currentOrderDetail.setTotal(BigDecimal.valueOf(getTotal()));
        currentOrderDetail.setProductId(product);
        currentOrderDetail.setShipId(oc.getCurrentShip());
    }
}
